package cn.liuyang.tinyioc.aop;

import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 方法处理器
 * Created by liuyang on 2018/4/10.
 */
public class ReflectiveMethodInvocation implements MethodInvocation {

    /**
     * 要执行方法的目标对象
     */
    private Object target;


    /**
     * 要执行的方法
     */
    private Method method;

    /**
     * 要执行的参数
     */
    private Object[] args;

    public ReflectiveMethodInvocation(Object target,Method method, Object[] args) {
        this.target = target;
        this.method = method;
        this.args = args;
    }

    @Override
    public Method getMethod() {
        return method;
    }

    @Override
    public Object[] getArguments() {
        return args;
    }

    @Override
    public Object proceed() throws Throwable {
        return method.invoke(target, args);
    }

    @Override
    public Object getThis() {
        return target;
    }

    @Override
    public AccessibleObject getStaticPart() {
        return method;
    }
}
